<template lang="pug">
	.add-parent-info-wrap
		.info-input-container
			input-line(leftText='姓名' placeholder="请输入该家长真实姓名" type="text" @getValue="getName")
			input-line(leftText='身份证号' placeholder="请输入该家长身份证号码" type="idcard" @getValue="getIdNumber" maxlength="18" :showBorder="false")
		.info-btn(@click="jumpToNext")
			main-button(text="下一步" :isActive="nextStepPass")
</template>

<script>
import inputLine from '@/components/input-line'
import mainButton from '@/components/main-button'
export default {
	name: 'addParentInfo',
	data() {
		return {
			name: '',
			idNumber: '',
			nextStepPassName: false,
			nextStepPassIdNumber: false
		}
	},
	computed: {
		nextStepPass() {
			return this.nextStepPassName && this.nextStepPassIdNumber
		}
	},
	created() {},
	mounted() {},
	methods: {
		jumpToNext() {
			if (this.nextStepPass) {
				this.submit()
			}
		},
		getName(text) {
			text = text.toString()
			this.name = text
			this.nextStepPassName = text.length > 0
		},
		getIdNumber(text) {
			text = text.toString()
			this.idNumber = text
			if (text.length === 15 || text.length === 18) {
				this.nextStepPassIdNumber = this.tools.identityCodeValid(text)
			} else {
				this.nextStepPassIdNumber = false
			}
		},
		submit() {
			let familyRole = this.wx.getStorageSync('familyRole')
			this.api.oneCardApi
				.judgeHouseholdRegister({
					idNumber: familyRole.idNumber,
					parentIdNumber: this.idNumber
				})
				.then(data => {
					if (data.responseFlag === '1') {
						familyRole = Object.assign(familyRole, {
							parentIdNumber: this.idNumber,
							parentName: this.name
						})
						this.wx.setStorage({
							key: 'familyRole',
							data: familyRole
						})
						this.$router.push({
							path: '/views/faceAuthtication/uploadIdPhoto'
						})
					} else {
						this.wx.showToast({
							title: data.responseMessage,
							icon: 'none'
						})
					}
				})
		}
	},
	components: {
		inputLine,
		mainButton
	}
}
</script>

<style lang="stylus">
	.add-parent-info-wrap
		.info-input-container
			margin-bottom mainMargin
			background-color white
		.info-btn
			width 690px
			height 92px
			margin 60px auto 0
			border-radius 46px
			overflow hidden
</style>
